<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
            text-decoration: none;
        }
        html,body {
            width: 100%;
            height: 100%;
        }
        #root {
            display: flex;
            width: 50%;
            height: 100%;
        }
        .left {
            width: 100px;
            height: 100%;
            background: blue;
            
        }
        .right {
            flex:9;
            height: 100%;
            display: none;

        }
        li:hover {
            background: pink;
        }
 




    </style>
</head>
<body>
    <div id="root"></div>
    <script>
        var app1 = {  // 描述左侧得虚拟dom对象
            type:"div",
            props:{
                class:"left",
                children:[
                    {
                        type:"h2",
                        props:{
                            children:["设置"]
                        }
                    }
                ]
            }
        }
        var app2 = {   // 对于右侧菜单得描述
            type:"ul",
            props:{
                class:"right",
                children:[
                    {
                        type:"li",
                        props:{
                            children:["项目公告"]
                        }
                    },
                    {
                        type:"li",
                        props:{
                            children:["成员管理"]
                        }
                    },
                    {
                        type:"li",
                        props:{
                            children:["分类标签"]
                        }
                    },
                    {
                        type:"li",
                        props:{
                            children:["项目设置"]
                        }
                    },
                    {
                        type:"li",
                        props:{
                            children:["仓库设置"]
                        }
                    },
                ]
            }
        }

    // 渲染虚拟dom
    function render (jsx,root) {
        let createElement = (jsx,parent)=>{ // 创建元素的方法
            let cur = null; // 用于承接创建出来的元素的
            if (typeof(jsx)=="string") {
                cur = document.createTextNode(jsx)
            } else {
                let {type,props} =jsx
                console.log(type,1111)
                cur = document.createElement(type)
                Object.keys(props).forEach((item,index)=>{
                    switch (item) {
                        case "class":
                             cur.setAttribute('class',props[item])
                            break;
                        case "children":
                          props[item].map((val)=>{
                              // 递归调用
                              createElement(val,cur)
                          })
                        break;
                    }

                })
            }
            parent.append(cur)

        }
        createElement(jsx,root)
    }

    render(app1,root)
    render(app2,root)
    var lefts = document.querySelector('.left');
    var rights = document.querySelector('.right');
    lefts.onmouseover = function() {
        rights.style.display = "block"
    }
    console.log(lefts)
   root.onmouseleave = function() {
        rights.style.display = "none"
    }


    </script>
</body>
</html>